// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/map/api/AreaMapApi'

import ComClass from '@api/ComQuery'

import ListClass from '@api/map/model/QueryAreaMapDeviceListReq'
import OneClass from '@api/map/model/QueryAreaMapDeviceDetailReq'
import AddClass from '@api/map/model/InsertAreaMapDeviceReq'
import DelClass from '@api/map/model/DeleteAreaMapDeviceReq'
import BaseClass from '@api/map/model/AreaMapDeviceDto'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'content']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询点位列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const { comQuery, content } = await CORE.grpc(TIP, CLIENT, 'queryAreaMapDeviceList', DTO)
    return [comQuery.totalCount, content]
  },

  // —————————————————————————————— 单项 —————————————————————————————— //

  async getOne({ id }, TIP = '查询点位详情') {
    const DTO = CORE.grpcDTO(OneClass, { id })
    const { content } = await CORE.grpc(TIP, CLIENT, 'queryAreaMapDeviceDetail', DTO)
    return content
  },

  // —————————————————————————————— 增 —————————————————————————————— //

  async add(one, TIP = '新增点位') {
    const DTO = CORE.grpcDTO(AddClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'insertAreaMapDevice', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 删 —————————————————————————————— //

  async del(one, TIP = '删除点位') {
    const DTO = CORE.grpcDTO(DelClass, one)
    await CORE.grpc(TIP, CLIENT, 'deleteAreaMapDevice', DTO)
    return CORE.grpcOK(TIP)
  },
}
